TDD 주기

테스트 주도 개발의 주기

  • Step 1. Quickly add a test.
  • Step 2. Run all tests and see the new one fail.
  • Step 3. Make a little change.
  • Step 4. Run all tests and see them all succeed.
  • Step 5. Refactor to remove duplication.

Write a test (Step 1 and 2)

Think about how you would like the operation in your mind to appear in your code. You are writing a story. Invent the interface you wish you had. Include all of the elements in the story that you imagine will be necessary to calculate the right answers.1

Make it run (Step 3 and 4)

Quickly getting that bar to go to green dominates everything else. If a clean, simple solution is obvious, then type it in. If the clean, simple solution is obvious but it will take you a minute, then make a note of it and get back to the main problem, which is getting the bar green in seconds. This shift in aesthetics is hard for some experienced software engineers. They only know how to follow the rules of good engineering. Quick green excuses all sins. But only for a moment.1

See also Three strategies for the green bar.

Make it right (Step 5)

Now that the system is behaving, put the sinful ways of the recent past behind you. Step back onto the straight and narrow path of software righteousness. Remove the duplication that you have introduced, and get to green quickly.1

See also

Footnotes

  1. Chapter 2, Test-driven development: by example 2 3

2024 © ak